<template>
    <div class="app-container">
      <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
       </el-row>
       <!-- 表格数据 -->
       <el-table v-loading="loading" :data="roleList">
          <el-table-column label="" prop="id">
            <template #default="scope">
                <span class="idx"  :style="{ backgroundColor: scope.$index < 3 ? 'black' : 'gray' }">
                  {{scope.$index + 1}}
                </span>
            </template>
          </el-table-column>
          <el-table-column label="用户头像" prop="=" :show-overflow-tooltip="true" >
            <template #default="scope">
              <span class="avatar" v-if="scope.row.friendUser.faceURL === ''">
                  {{scope.row.friendUser.nickname[0]}}
              </span>
              <div v-else>
                <img :src="scope.row.faceURL" alt="light" />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="用户呢称" :show-overflow-tooltip="true" >
            <template #default="scope">
                <span>
                  {{scope.row.friendUser.nickname}}
                </span>
            </template>
          </el-table-column>
          <el-table-column label="用户ID">
            <template #default="scope">
                <span>
                  {{scope.row.friendUser.userID}}
                </span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
             <template #default="scope">
                 <el-button link type="primary"  @click="handleDelete(scope.row)">删除</el-button>
             </template>
          </el-table-column>
       </el-table>
       
       <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
       />
    </div>
 </template>
 
 <script setup name="relationList">
 import { getRelationList, deleteRelation } from "@/api/im/user";
 import { ref, onMounted } from "vue";
 
 const router = useRouter();
 const route = useRoute()
 const { proxy } = getCurrentInstance();
 
 const roleList = ref([]);
 const loading = ref(true);
 const total = ref(0);
 const dateRange = ref([]);
 const openDataScope = ref(false);
 const userID = ref('');
 
 onMounted(() => {
    userID.value = route.params.userID;
    getList();
})
 const data = reactive({
   form: {},
   queryParams: {
     pageNum: 1,
     pageSize: 10,
   },
   pageObj:{
    pageNumber: 1,
    showNumber: 10
   },
   rules: {
     roleName: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }],
     iphone: [{ required: true, message: "手机号不能为空", trigger: "blur" }],
     password: [{ required: true, message: "密码不能为空", trigger: "blur" }]
   },
 });
 
 const { queryParams, pageObj } = toRefs(data);
 
 /** 查询角色列表 */
 function getList() {
   loading.value = true;
   const params = {
      pagination: pageObj.value,
      userID: userID.value
   }
   getRelationList(params).then(response => {
     roleList.value = response.data.friendsInfo;
     total.value = response.data.total;
     loading.value = false;
   });
 }
 
 /** 搜索按钮操作 */
 function handleQuery() {
   queryParams.value.pageNum = 1;
   getList();
 }
 
 /** 重置按钮操作 */
 function resetQuery() {
   dateRange.value = [];
   proxy.resetForm("queryRef");
   handleQuery();
 }
 
 /** 更多操作 */
 function handleCommand(command, row) {
   switch (command) {
     case "handleDataScope":
       handleDataScope(row);
       break;
     case "handleAuthUser":
       handleAuthUser(row);
       break;
     default:
       break;
   }
 }
 
 /** 分配用户 */
 function handleAuthUser(row) {
   router.push("/system/role-auth/user/" + row.roleId);
 }

 /** 取消按钮 */
 function cancel() {
   open.value = false;
   reset();
 }
 /** 取消按钮（数据权限）*/
 function cancelDataScope() {
   openDataScope.value = false;
   reset();
 }
 function handleDelete (row) {
  const params = {
    friendUserID: row.friendUser.userID,
    ownerUserID: row.ownerUserID,
  }
  proxy.$modal.confirm('是否确认移除该用户').then(function () {
     return deleteRelation(params);
   }).then(() => {
     getList();
     proxy.$modal.msgSuccess("移除成功");
   }).catch(() => {});
 }
 </script>
<style scoped>
.upload_c{
    margin-bottom: 10px;
}
.upload_text{
    text-align: center;
    margin: 0 auto;
    margin-top: 10px;
    color: #1890ff;
    font-size: 14px;
}
.upload{
    width: 53px;
    height: 53px;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f5f5f5;
    margin: 0 auto;
}
</style>
 